﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;

namespace PropGridInfo
{
	public class XPropsLst : List<XPropItem>, ICustomTypeDescriptor
	{
		public AttributeCollection GetAttributes()
		{
			return TypeDescriptor.GetAttributes(this, true);
		}

		public string GetClassName()
		{
			return TypeDescriptor.GetClassName(this, true);
		}

		public string GetComponentName()
		{
			return TypeDescriptor.GetComponentName(this, true);
		}

		public TypeConverter GetConverter()
		{
			return TypeDescriptor.GetConverter(this, true);
		}

		public EventDescriptor GetDefaultEvent()
		{
			return TypeDescriptor.GetDefaultEvent(this, true);
		}

		public PropertyDescriptor GetDefaultProperty()
		{
			return TypeDescriptor.GetDefaultProperty(this, true);
		}

		public object GetEditor(Type editorBaseType)
		{
			return TypeDescriptor.GetEditor(this, editorBaseType, true);
		}

		public EventDescriptorCollection GetEvents(Attribute[] attributes)
		{
			return TypeDescriptor.GetEvents(this, attributes, true);
		}

		public EventDescriptorCollection GetEvents()
		{
			return TypeDescriptor.GetEvents(this, true);
		}

		public PropertyDescriptorCollection GetProperties(Attribute[] attributes)
		{
			ArrayList arrayList = new ArrayList();
			for (int i = 0; i < base.Count; i++)
			{
				bool browsable = base[i].Browsable;
				if (browsable)
				{
					XPropDescriptor value = new XPropDescriptor(base[i], attributes);
					arrayList.Add(value);
				}
			}
			for (int j = 0; j < arrayList.Count - 1; j++)
			{
				for (int k = j + 1; k < arrayList.Count; k++)
				{
					bool flag = ((XPropDescriptor)arrayList[j]).Order > ((XPropDescriptor)arrayList[k]).Order;
					if (flag)
					{
						XPropDescriptor value2 = (XPropDescriptor)arrayList[j];
						arrayList[j] = arrayList[k];
						arrayList[k] = value2;
					}
				}
			}
			ArrayList arrayList2 = new ArrayList();
			foreach (object obj in arrayList)
			{
				XPropDescriptor xpropDescriptor = (XPropDescriptor)obj;
				arrayList2.Add(xpropDescriptor.Name);
			}
			PropertyDescriptor[] properties = (PropertyDescriptor[])arrayList.ToArray(typeof(PropertyDescriptor));
			PropertyDescriptorCollection propertyDescriptorCollection = new PropertyDescriptorCollection(properties);
			return propertyDescriptorCollection.Sort((string[])arrayList2.ToArray(typeof(string)));
		}

		public PropertyDescriptorCollection GetProperties()
		{
			return TypeDescriptor.GetProperties(this, true);
		}

		public object GetPropertyOwner(PropertyDescriptor pd)
		{
			return this;
		}

		public override string ToString()
		{
			StringBuilder stringBuilder = new StringBuilder();
			for (int i = 0; i < base.Count; i++)
			{
				stringBuilder.Append(string.Concat(new object[]
				{
					"[",
					i,
					"] ",
					base[i].ToString(),
					Environment.NewLine
				}));
			}
			return stringBuilder.ToString();
		}
	}
}
